package com.planet.stockanalysis.server.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.planet.stockanalysis.server.dao.UserDao;
import com.planet.stockanalysis.server.entity.User;
import com.planet.stockanalysis.server.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService { 

	@Autowired
	private UserDao userDao; 

	public User createNewAccount(String username, String password, Integer initBalance){ 
		// 封装域对象
		User userInfo = new User(); 
		userInfo.setUsername(username); 
		userInfo.setPassword(password); 
		// 调用持久层，完成数据的保存
		return userDao.save(userInfo);
	}

	public User login(String username, String password){
		List<User> users = userDao.findByNameAndPassword(username, password);
		if(users.size() > 0)
			return users.get(0);
		else
			return null;
	}

	@Override
	public User findById(long id) {
		// TODO Auto-generated method stub
		return userDao.findOne(id);
	}
} 